#pragma once

#include <string>
using std::string;

class auto_setlocate
{
public:
	auto_setlocate()
	{
		setlocale(LC_ALL, "");
	}
};

#pragma warning(disable: 4996)
inline std::string wstring2string(const wchar_t* wsz)
{
	/*static*/ auto_setlocate as;
	std::string ret(wcslen(wsz)*2, '\0');
	std::wcstombs(const_cast<char*>(ret.c_str()), wsz, ret.length());
	return std::string(ret.c_str());
}

inline std::string wstring2string(const std::wstring& wstr)
{
	/*static*/ auto_setlocate as;
	std::string ret(wstr.length()*2, '\0');
	std::wcstombs(const_cast<char*>(ret.c_str()), wstr.c_str(), wstr.length()*2);
	return std::string(ret.c_str());
}

inline std::wstring string2wstring(const char* sz)
{
	/*static*/ auto_setlocate as;
	std::wstring ret(strlen(sz), '\0');
	std::mbstowcs(const_cast<wchar_t*>(ret.c_str()), sz, ret.length());
	return std::wstring(ret.c_str());
}

inline std::wstring string2wstring(const std::string& str)
{    
	/*static*/ auto_setlocate as;
	std::wstring ret(str.length(), '\0');
	std::mbstowcs(const_cast<wchar_t*>(ret.c_str()), str.c_str(), str.length());
	return std::wstring(ret.c_str());
}